def main():

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        subprocess.call('clear')

        item = json.load(grpc_file)

        creds = item["grpc"]["DeleteDocuments"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        # name is defined in the grpc.json file
        name = item["grpc"]["DeleteDocuments"]["name"]

        if name == ' ':

            name = raw_input(
                "Please enter the resource name of the document to delete, e.g. project/{project_id}/databases/{database_id}/documents/{document_path}: \n"
            )

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        delete_document_request = firestore_pb2.DeleteDocumentRequest(
            name=name)
        stub.DeleteDocument(delete_document_request)
 def test_with_scopes_provide_default_scopes(self):
     credentials = self.make_credentials()
     credentials._target_scopes = []
     credentials = credentials.with_scopes(
         ["fake_scope1"], default_scopes=["fake_scope2"]
     )
     assert credentials._target_scopes == ["fake_scope1"]
示例#3
0
def main():

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["Rollback"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        database = item["grpc"]["Rollback"]["database"]

        begin_transaction_request = firestore_pb2.BeginTransactionRequest(
            database=database)
        begin_transaction_response = stub.BeginTransaction(
            begin_transaction_request)

        rollback_request = firestore_pb2.RollbackRequest(
            database=database,
            transaction=begin_transaction_response.transaction)
        rollback_response = stub.Rollback(rollback_request)
        print(rollback_response)
 def test_with_scopes(self):
     credentials = self.make_credentials()
     credentials._target_scopes = []
     assert credentials.requires_scopes is True
     credentials = credentials.with_scopes(["fake_scope1", "fake_scope2"])
     assert credentials.requires_scopes is False
     assert credentials._target_scopes == ["fake_scope1", "fake_scope2"]
def main():

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["UpdateDocument"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        now = time.time()
        seconds = int(now)
        timestamp = timestamp_pb2.Timestamp(seconds=seconds)

        # name is set in the grpc.json file
        name = item["grpc"]["UpdateDocument"]["name"]

        if name == ' ':
            name = raw_input(
                "Please provide the resource name of the document to be updated: \n"
            )

        field = raw_input(
            'Please provide the field to be updated, e.g. "foo" ')
        current_value = raw_input(
            'Please provide the current value of the field to be updated, e.g. "bar"  '
        )

        update_mask = common_pb2.DocumentMask(
            field_paths=[field, current_value])

        value = raw_input(
            "Please provide the new value of the field to update using the following syntax, e.g. 'foo_boo' \n"
        )

        value_ = document_pb2.Value(string_value=value)

        document = document_pb2.Document(name=name, fields={field: value_})

        update_document_request = firestore_pb2.UpdateDocumentRequest(
            document=document,
            update_mask=common_pb2.DocumentMask(field_paths=[field]))
        update_document_response = stub.UpdateDocument(update_document_request)

        print(update_document_response)
示例#6
0
def main():

   subprocess.call('clear')
    
   fl = os.path.dirname(os.path.abspath(__file__))
   fn = os.path.join(fl, 'grpc.json')

   with open(fn) as grpc_file:
          
            item = json.load(grpc_file)

            creds = item["grpc"]["CreateIndex"]["credentials"]

            credentials = service_account.Credentials.from_service_account_file("{}".format(creds))
            scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/datastore'])
            http_request = google.auth.transport.requests.Request()
            channel = google.auth.transport.grpc.secure_authorized_channel(scoped_credentials, http_request, 'firestore.googleapis.com:443')


            stub = firestore_admin_pb2_grpc.FirestoreAdminStub(channel)

            # name, parent and collection_id are definded in the grpc.json file
            name = item["grpc"]["CreateIndex"]["name"]
            parent = item["grpc"]["CreateIndex"]["parent"]
            collection_id = item["grpc"]["CreateIndex"]["collection_id"]
              
            fields = []
                     
            # field_path1 and mode1 are defined in the grpc.json file         
            field_path1= item["grpc"]["CreateIndex"]["field_path1"] 
            mode1= item["grpc"]["CreateIndex"]["mode1"]

            fields1 = index_pb2.IndexField(field_path=field_path1, mode=mode1)

                  
            # field_path2 and mode2 are defined in the grpc.json file         
            field_path2= item["grpc"]["CreateIndex"]["field_path2"] 
            mode2= item["grpc"]["CreateIndex"]["mode2"]
                     
            fields2 = index_pb2.IndexField(field_path=field_path2, mode=mode2)

            fields = [fields1, fields2]
                     
            index = index_pb2.Index(name=name, collection_id=collection_id, fields=fields)

            create_index_request = firestore_admin_pb2.CreateIndexRequest(parent=parent, index=index)
            create_index_response = stub.CreateIndex(create_index_request)

            print(create_index_response)
示例#7
0
def main():

    subprocess.call('clear')

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["GetDocument"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        now = time.time()
        seconds = int(now)
        timestamp = timestamp_pb2.Timestamp(seconds=seconds)

        field_paths = {}

        # field_paths is set in the grpc.json file
        field_paths = item["grpc"]["GetDocument"]["document_mask_field_path"]

        mask = common_pb2.DocumentMask(field_paths=[field_paths])

        # name is set in the grpc.json file
        name = item["grpc"]["GetDocument"]["name"]

        if name == ' ':

            name = raw_input(
                "Please enter the resource name of the Document to get, e.g. projects/{project_id}/databases/{database_id}/documents/{document_path}: \n"
            )

        get_document_request = firestore_pb2.GetDocumentRequest(name=name,
                                                                mask=mask)
        get_document_response = stub.GetDocument(get_document_request)

        print(get_document_response)
示例#8
0
def main():

    subprocess.call('clear')

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["DeleteIndex"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_admin_pb2_grpc.FirestoreAdminStub(channel)

        # parent definded in the grpc.json file
        parent = item["grpc"]["DeleteIndex"]["parent"]

        list_indexes_request = firestore_admin_pb2.ListIndexesRequest(
            parent=parent)
        list_indexes_response = {}
        list_indexes_response = stub.ListIndexes(list_indexes_request)

        print("\n")
        for index in list_indexes_response.indexes:
            print(index.name)

        print("\n")

        name = raw_input("Please enter the index to delete: \n")

        stub = firestore_admin_pb2_grpc.FirestoreAdminStub(channel)

        delete_index_request = firestore_admin_pb2.DeleteIndexRequest(
            name=name)
        stub.DeleteIndex(delete_index_request)
def main():

    subprocess.call('clear')

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["CreateDocument"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        # parent defined in the grpc.json file
        parent = item["grpc"]["CreateDocument"]["parent"]

        # collection_id defined in the grpc.json
        collection_id = item["grpc"]["CreateDocument"]["collection_id"]

        document_id = item["grpc"]["CreateDocument"]["document_id"]

        if document_id == ' ':

            document_id = raw_input("Please provde a document_id: \n")

        document = {}

        create_document_request = firestore_pb2.CreateDocumentRequest(
            parent=parent,
            collection_id=collection_id,
            document_id=document_id,
            document=document)
        document = stub.CreateDocument(create_document_request)
        print(document)
示例#10
0
def main():

    subprocess.call('clear')

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        # credentials file location defined in grpc.json file
        creds = item["grpc"]["BeginTransaction"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        now = time.time()
        seconds = int(now)
        timestamp = timestamp_pb2.Timestamp(seconds=seconds)

        # database definded in grpc.json file
        database = item["grpc"]["BeginTransaction"]["database"]

        options = common_pb2.TransactionOptions(
            read_only=common_pb2.TransactionOptions.ReadOnly(
                read_time=timestamp))

        begin_transaction_request = firestore_pb2.BeginTransactionRequest(
            database=database, options=options)

        begin_transaction_response = stub.BeginTransaction(
            begin_transaction_request)

        print(begin_transaction_response)
示例#11
0
def main():

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["Write"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        database = item["grpc"]["Write"]["database"]
        name = item["grpc"]["Write"]["name"]
        first_write = write_pb2.Write()

        responses = stub.Write(first_message(database, first_write))
        for response in responses:
            print("Received message %s" % (response.stream_id))
            print(response.stream_token)

        value_ = document_pb2.Value(string_value="foo_boo")
        update = document_pb2.Document(name=name, fields={"foo": value_})
        writes = write_pb2.Write(
            update_mask=common_pb2.DocumentMask(field_paths=["foo"]),
            update=update)
        r2 = stub.Write(
            generate_messages(database, writes, response.stream_id,
                              response.stream_token))
        for r in r2:
            print(r.write_results)
示例#12
0
def main():

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["RunQuery"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        parent = item["grpc"]["RunQuery"]["parent"]
        field_path = item["grpc"]["RunQuery"]["field_path"]

        fields = {}
        fields = query_pb2.StructuredQuery.FieldReference(
            field_path=field_path)
        select = query_pb2.StructuredQuery.Projection(fields=[fields])

        structured_query = query_pb2.StructuredQuery(select=select)

        run_query_request = firestore_pb2.RunQueryRequest(
            parent=parent, structured_query=structured_query)
        run_query_response = stub.RunQuery(run_query_request)

        print('starting read from batch: ', type(run_query_response))
        for runquery in run_query_response:
            print(runquery)
def main():

  subprocess.call('clear')

  fl = os.path.dirname(os.path.abspath(__file__))
  fn = os.path.join(fl, 'grpc.json')

  with open(fn) as grpc_file:
         
     item = json.load(grpc_file)

     creds = item["grpc"]["BatchGetDocuments"]["credentials"]

     credentials = service_account.Credentials.from_service_account_file("{}".format(creds))
     scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/datastore'])
     http_request = google.auth.transport.requests.Request()
     channel = google.auth.transport.grpc.secure_authorized_channel(scoped_credentials, http_request, 'firestore.googleapis.com:443')

     stub = firestore_pb2_grpc.FirestoreStub(channel)
     
     # database and documents defined in the grpc.json file
     database = item["grpc"]["BatchGetDocuments"]["database"]
     documents = item["grpc"]["BatchGetDocuments"]["documents"]

     if documents == ' ':

        print("Please enter the document Id's you would like to retrieve, e.g.\n")
        print("projects/geoff-python/databases/(default)/documents/users/alovelace \n") 
      
        documents = raw_input(":")

     batch_get_document_request = firestore_pb2.BatchGetDocumentsRequest(database = database, documents = [documents])
     batch_get_document_response = stub.BatchGetDocuments(batch_get_document_request)
                     
     print('staring read from batch: ', type(batch_get_document_response))
     for get_document in batch_get_document_response:
       	    print(get_document)
def main():

   subprocess.call('clear')

   fl = os.path.dirname(os.path.abspath(__file__))
   fn = os.path.join(fl, 'grpc.json')

   with open(fn) as grpc_file:
          
            item = json.load(grpc_file)

            creds = item["grpc"]["ListCollectionIds"]["credentials"]

            credentials = service_account.Credentials.from_service_account_file("{}".format(creds))
            scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/datastore'])
            http_request = google.auth.transport.requests.Request()
            channel = google.auth.transport.grpc.secure_authorized_channel(scoped_credentials, http_request, 'firestore.googleapis.com:443')

            stub = firestore_pb2_grpc.FirestoreStub(channel)

            parent = item["grpc"]["ListCollectionIds"]["parent"]
            list_collectionIds_request = firestore_pb2.ListCollectionIdsRequest(parent = parent)
            list_collectionIds_response = stub.ListCollectionIds(list_collectionIds_request)
            print(list_collectionIds_response)
示例#15
0
def main():


   fl = os.path.dirname(os.path.abspath(__file__))
   fn = os.path.join(fl, 'grpc.json')

   with open(fn) as grpc_file:
          
            item = json.load(grpc_file)

            creds = item["grpc"]["ListDocuments"]["credentials"]

            credentials = service_account.Credentials.from_service_account_file("{}".format(creds))
            scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/datastore'])
            http_request = google.auth.transport.requests.Request()
            channel = google.auth.transport.grpc.secure_authorized_channel(scoped_credentials, http_request, 'firestore.googleapis.com:443')

            stub = firestore_pb2_grpc.FirestoreStub(channel)

            parent = item["grpc"]["ListDocuments"]["parent"]

            list_document_request = firestore_pb2.ListDocumentsRequest(parent = 'projects/geoff-python/databases/(default)/documents')
            list_document_response = stub.ListDocuments(list_document_request)
            print(list_document_response)
示例#16
0
def main():

    subprocess.call('clear')

    fl = os.path.dirname(os.path.abspath(__file__))
    fn = os.path.join(fl, 'grpc.json')

    with open(fn) as grpc_file:

        item = json.load(grpc_file)

        creds = item["grpc"]["Commit"]["credentials"]

        credentials = service_account.Credentials.from_service_account_file(
            "{}".format(creds))
        scoped_credentials = credentials.with_scopes(
            ['https://www.googleapis.com/auth/datastore'])
        http_request = google.auth.transport.requests.Request()
        channel = google.auth.transport.grpc.secure_authorized_channel(
            scoped_credentials, http_request, 'firestore.googleapis.com:443')

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        now = time.time()
        seconds = int(now)
        timestamp = timestamp_pb2.Timestamp(seconds=seconds)

        # database defined in the grpc.json file
        database = item["grpc"]["Commit"]["database"]

        options = common_pb2.TransactionOptions(
            read_write=common_pb2.TransactionOptions.ReadWrite())
        begin_transaction_request = firestore_pb2.BeginTransactionRequest(
            database=database, options=options)
        begin_transaction_response = stub.BeginTransaction(
            begin_transaction_request)
        transaction = begin_transaction_response.transaction

        stub = firestore_pb2_grpc.FirestoreStub(channel)

        now = time.time()
        seconds = int(now)
        timestamp = timestamp_pb2.Timestamp(seconds=seconds)

        field_paths = {}
        # document mask field_path is defined in the grpc.json file
        field_paths = item["grpc"]["Commit"]["field_paths"]
        update_mask = common_pb2.DocumentMask(field_paths=[field_paths])

        # document_fileds is defined in the grpc.json file
        fields = item["grpc"]["Commit"]["fields"]

        # document_name is defined in the grpc.json file
        name = item["grpc"]["Commit"]["name"]

        update = document_pb2.Document(name=name,
                                       fields=fields,
                                       create_time=timestamp,
                                       update_time=timestamp)

        writes = {}
        database = item["grpc"]["Commit"]["database"]
        writes = write_pb2.Write(update_mask=update_mask, update=update)

        commit_request = firestore_pb2.CommitRequest(database=database,
                                                     writes=[writes],
                                                     transaction=transaction)
        commit_response = stub.Commit(commit_request)

        print(commit_response)
示例#17
0
 def test_create_scoped(self):
     credentials = self.make_credentials()
     with pytest.raises(NotImplementedError):
         credentials.with_scopes(['email'])
from subprocess import check_output
import urllib
import urllib3
import time

import google.auth
from google.auth.transport.requests import AuthorizedSession
import google.oauth2.credentials
from google.oauth2 import service_account
from google.auth import impersonated_credentials

urllib3.disable_warnings()
credentials = service_account.Credentials.from_service_account_file(
    './app_controllers/secrets/oauth2.json')
scoped_credentials = credentials.with_scopes([
    'https://www.googleapis.com/auth/userinfo.profile',
    'https://www.googleapis.com/auth/userinfo.email'
])
print("CREDENTIALS:", scoped_credentials)
authed_session = AuthorizedSession(scoped_credentials)
print("AUTHORIZED:", authed_session)
"""
1. deploy,service,ingress - done
2. install plugin/extension via cli/script
3. connect to gitlab
3. connect to kubernetes host
4. trigger from gitlab push
5. deploy to kubernetes
"""


# Installs Gitlab & Git Plugin