Edits history of script submission #1273 for ' Get a project deploy key (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get a project deploy key
     * Returns the deploy key belonging to a specific key ID.
     */
    export async function main(
      auth: Bitbucket,
      key_id: string,
      project_key: string,
      workspace: string
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/deploy-keys/${key_id}`
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 375 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get a project deploy key
     * Returns the deploy key belonging to a specific key ID.
     */
    export async function main(
      auth: Bitbucket,
      key_id: string,
      project_key: string,
      workspace: string
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/deploy-keys/${key_id}`
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 935 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get a project deploy key
     * Returns the deploy key belonging to a specific key ID.
    
    Example:
    ```
    $ curl -H "Authorization <auth header>" \
    https://api.bitbucket.org/2.0/workspaces/standard/projects/TEST_PROJECT/deploy-keys/1234
    
    Output:
    {
        "pagelen":10,
        "values":[
            {
                "comment":"thakseth@C02W454JHTD8",
                "last_used":null,
                "links":{
                    "self":{
                        "href":"https://api.bitbucket.org/2.0/workspaces/standard/projects/TEST_PROJECT/deploy-keys/1234"
                    }
                },
                "label":"test",
                "project":{
                    "links":{
                        "self":{
                            "href":"https://api.bitbucket.org/2.0/workspaces/standard/projects/TEST_PROJECT"
                        }
                    },
                    "type":"project",
                    "name":"cooperative standard",
                    "key":"TEST_PROJECT",
                    "uuid":"{3b3e510b-7f2b-414d-a2b7-76c4e405c1c0}"
                },
                "created_on":"2021-07-28T21:20:19.491721+00:00",
                "key":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDX5yfMOEw6HG9jKTYTisbmDTJ4MCUTSVGr5e4OWvY3UuI2A6F8SdzQqa2f5BABA/4g5Sk5awJrYHlNu3EzV1V2I44tR3A4fnZAG71ZKyDPi1wvdO7UYmFgxV/Vd18H9QZFFjICGDM7W0PT2mI0kON/jN3qNWi+GiB/xgaeQKSqynysdysDp8lnnI/8Sh3ikURP9UP83ShRCpAXszOUNaa+UUlcYQYBDLIGowsg51c4PCkC3DNhAMxppkNRKoSOWwyl+oRVXHSDylkiJSBHW3HH4Q6WHieD54kGrjbhWBKdnnxKX7QAAZBDseY+t01N36m6/ljvXSUEcBWtHxBYye0r",
                "type":"project_deploy_key",
                "id":1234
            }
        ],
    }
    ```
     */
    export async function main(
      auth: Bitbucket,
      key_id: string,
      project_key: string,
      workspace: string
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/deploy-keys/${key_id}`
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 935 days ago